﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _80X_CG_Frame.Workers
{
    /// <summary>
    /// 可释放的worker
    /// </summary>
    public class DisposeWorker : IDisposable
    {
        //PLCTaskWorker plcTaskWoker;
        RunWorker_802 runWorker_802;
        RunWorker_803 runWorker_803;
        public DisposeWorker()
        {
            if (GLOBAL.config.Get("机台类型") == "802")
            {
                runWorker_802 = new RunWorker_802();
                if (!runWorker_802.IsRunning())
                {
                    runWorker_802.Start();
                }
            }
            else
            {
                runWorker_803 = new RunWorker_803();
                if (!runWorker_803.IsRunning())
                {
                    runWorker_803.Start();
                }
            }
            /*plcTaskWoker = new PLCTaskWorker(global);
            if (!plcTaskWoker.IsRunning())
            {
                plcTaskWoker.Start();
            }
            */
        }

        public void Dispose()
        {
            if(runWorker_802 != null)
                runWorker_802.Cancel();
            if (runWorker_803 != null)
                runWorker_803.Cancel();
            System.Threading.Thread.Sleep(500);
        }

        public async Task DisposeAsync()
        {
            await Task.Run(()=>
            {
                Dispose();
            }
            );
        }
        
    }
}
